<template>
	<view class="content">
		<view class="title" :style="'background-color:'+themeColor.main_color">
			商品分类
		</view>
		
		<view v-if="getCategoryOneList.length > 0">
			<cc-categorizeView @currentIdClick="currentIdClick" :currentId="categoryCurrent" :height="((screenHeight-61)+'px')" :main_clor="themeColor.main_color" :flist="getCategoryOneList" :slist="slist" :tlist="tlist" @itemClick="navToList"></cc-categorizeView>
		</view>

		<nuoyu-tabbar :backgroundColor="themeColor.tabbarColor" :color="themeColor.font_assist" :selectedColor="themeColor.main_color" :current="current" :tabBar="tabBar"></nuoyu-tabbar>
	</view>
</template>

<script>

export default {
	  data() {
		return {
			flist: [],
			slist: [],
			tlist: [],
			current: 1,
			tabBar:[],
			themeColor:'',
			wechatConfig:'',
			list:[],
			getCategoryOneList:[],
			screenHeight:0,
			categoryCurrent:0
			
		}
	  },
	onLoad() {
		const info = uni.getSystemInfoSync();
		this.tabBar = this.$store.state.tabBarList || uni.getStorageSync('tabbar')
		this.current = this.$store.state.current || 1
		this.themeColor = this.$store.state.themeConfig || uni.getStorageSync('themeConfig')
		this.wechatConfig = this.$store.state.wechatConfig ||  uni.getStorageSync('wechatConfig')
		this.screenHeight = info.screenHeight;
		console.log(this.screenHeight)
		this.getCategoryOne()
	},
	onShow() {
		 
	},
	methods: {
		currentIdClick(item){
			 
			this.categoryCurrent = item.id
			this.getCategoryTow(item)
		},
		// 一级菜单
		getCategoryOne(){
			this.tui.request("/basic-capi/category/getCategoryOne", "get",
			 ).then(res=>{
				if(res.code == 200){
					this.getCategoryOneList = res.data.list
					this.categoryCurrent = res.data.list[0].id
					this.getCategoryTow(this.getCategoryOneList[0])
				} 
			})
		},
		// 二级
		getCategoryTow(item){
			this.tui.request("/basic-capi/category/getCategoryTow", "get",
			{
				list:item.id
			}
			 ).then(res=>{
				if(res.code == 200){
					var data = []
					for (var i = 0; i < res.data.list.length; i++) {
						data.push(...res.data.list[i])
					}
			
					this.slist = data
					this.getCategoryThs(this.slist)
				
				} 
			})
			
		},
		// 三级级
		getCategoryThs(item){
			var strs = ''
			let that = this
			item.map((res,index)=>{
				if(index == 0)
					strs += res.id
				else
					strs += ','+res.id  
			})
			that.tui.request("/basic-capi/category/getCategoryTow", "get",
				{
					list:strs
				}
			 ).then(res=>{
				if(res.code == 200){
					 
					var data = []
					for (var i = 0; i < res.data.list.length; i++) {
						for (var j = 0; j < res.data.list[i].length; j++) {
						 
							data.push({
								id:res.data.list[i][j].id,
								name:res.data.list[i][j].name,
								pid:Number(res.data.list[i][j].pid),
								picture:that.wechatConfig.tencent‌Domain + res.data.list[i][j].picture
							})
							
						}
						
						
					}
				
					that.tlist = data
					
				
				} 
			})
			
		},
		 navToList(item) {
			console.log(item)
			uni.navigateTo({
				url:"/pages/goods/goodsTypeList?id="+item.id
			})
			
			 // uni.showModal({
				//  title: '温馨提示',
				//  content: '点击条目携带信息 = ' + JSON.stringify(item)
			 // })
		 }
	}
	 
}
</script>

<style lang="scss">
	page,
	.content {
		// position: fixed;
		height: 100vh;
		background-color: #f8f8f8;
	}
	.title{
		display: flex;
		justify-content: center;
		align-items: center;
		height: 60px;
		font-size: 32rpx;
		color: #fff;
	}
</style>
